package com.kexio.enterprise.governance.retry.result;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 重试结果
 * 
 * @param <T> 结果类型
 * @author Kexio
 * @since 1.0.0
 */
public class RetryResult<T> {
    private boolean success;
    private T result;
    private Throwable lastException;
    private int attemptCount;
    private long totalExecutionTime;
    private boolean fromFallback;
    private String reason;
    private LocalDateTime startTime;
    private LocalDateTime endTime;
    private List<RetryAttempt> attempts;
    private Map<String, Object> metadata;

    public RetryResult(boolean success) {
        this.success = success;
        this.startTime = LocalDateTime.now();
        this.attempts = new ArrayList<>();
    }

    public RetryResult(T result) {
        this.success = true;
        this.result = result;
        this.startTime = LocalDateTime.now();
        this.attempts = new ArrayList<>();
    }

    public RetryResult(Throwable exception) {
        this.success = false;
        this.lastException = exception;
        this.startTime = LocalDateTime.now();
        this.attempts = new ArrayList<>();
    }

    // Getters and Setters
    public boolean isSuccess() { return success; }
    public void setSuccess(boolean success) { this.success = success; }
    
    public T getResult() { return result; }
    public void setResult(T result) { this.result = result; }
    
    public Throwable getLastException() { return lastException; }
    public void setLastException(Throwable lastException) { this.lastException = lastException; }
    
    public int getAttemptCount() { return attemptCount; }
    public void setAttemptCount(int attemptCount) { this.attemptCount = attemptCount; }
    
    public long getTotalExecutionTime() { return totalExecutionTime; }
    public void setTotalExecutionTime(long totalExecutionTime) { this.totalExecutionTime = totalExecutionTime; }
    
    public boolean isFromFallback() { return fromFallback; }
    public void setFromFallback(boolean fromFallback) { this.fromFallback = fromFallback; }
    
    public String getReason() { return reason; }
    public void setReason(String reason) { this.reason = reason; }
    
    public LocalDateTime getStartTime() { return startTime; }
    public void setStartTime(LocalDateTime startTime) { this.startTime = startTime; }
    
    public LocalDateTime getEndTime() { return endTime; }
    public void setEndTime(LocalDateTime endTime) { this.endTime = endTime; }
    
    public List<RetryAttempt> getAttempts() { return attempts; }
    public void setAttempts(List<RetryAttempt> attempts) { this.attempts = attempts; }
    
    public Map<String, Object> getMetadata() { return metadata; }
    public void setMetadata(Map<String, Object> metadata) { this.metadata = metadata; }
}
